package leetcode;

import java.time.LocalDate;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * @program: datastructureandalogorithm
 * @description:
 * @author: hmx
 * @create: 2022-01-03 00:34
 **/
public class LeetCode1185 {

    //api
    /*public String dayOfTheWeek(int day, int month, int year) {
        String[] strs = new String[]{"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
        //获取日历类实例
        Calendar instance = Calendar.getInstance();
        //设置年月日,1-12要映射成0-11,所以month-1
        instance.set(year, month - 1, day);
        //instance.get(Calendar.DAY_OF_WEEK)返回的是1-7,从周日开始,所以也要减一
        return strs[instance.get(Calendar.DAY_OF_WEEK) - 1];
    }*/

    public String dayOfTheWeek(int day, int month, int year) {
        String[] week = {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"};
        int[] monthDays = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30};
        // 输入年份之前的年份的天数贡献, (year - 1969) / 4是闰年的个数
        int days = 365 * (year - 1971) + (year - 1969) / 4;
        /* 输入年份中，输入月份之前的月份的天数贡献 */
        for (int i = 0; i < month - 1; ++i) {
            days += monthDays[i];
        }
        if ((year % 400 == 0 || (year % 4 == 0 && year % 100 != 0)) && month >= 3) {
            days += 1;
        }
        /* 输入月份中的天数贡献 */
        days += day;
        return week[(days + 3) % 7];
    }




}
